import http from '@/utils/request'

//  获取分发文件 旧
// const getFileList = (data, config) => {
//     let url = `/sendfile/media/manage/terminalPage`
//     return http.get(url, {params: data}, config)
// }

//  获取分发文件
const getFileList = (data, config) => {
    let url = `/sendfile/media/manage/terminalPage`
    return http.get(url, {params: data}, config)
}

// 快捷列表
const getQuickOperateList = (data, config) => {
    let url = `/sendfile/media/quickly/page`
    return http.get(url, {params: data}, config)
}

export const getFileListByTerminalId = (clientId=0, type=1, parentId=0, fileType=null, mediaType=null) => {
    return new Promise(async (resolve, reject) => {

        const getFileParams = {
            parentId: parentId,
            type: type,
            audit: 1,
            fileType: fileType,
            mediaType: mediaType != 0 ? mediaType : null,
            clientId: clientId
        }

        const fileAllList = await getFileList(getFileParams, {})
        let fileList = []
        resolve(fileAllList.data)
    })
}

//旧版
// export const getFileListByTerminalId = (terminalId=0, fileType=1, parentId=0) => {
//     return new Promise(async (resolve, reject) => {
//         const getQuickParams = {
//             quicklyName: '',
//             page: 1,
//             pageSize: 200000000
//         }

//         const quickList = await getQuickOperateList(getQuickParams, {})
//         const getFileParams = {
//             mediaType: '',
//             // fileType: 2,
//             parentId: parentId,
//             page: 1,
//             pageSize: 200000000
//         }

//         const filterQuickList = quickList.data.records.filter(item => item.client_id.indexOf(terminalId) !== -1)

//         console.log('filterQuickList ---', filterQuickList)
//         // 获取素材id
//         let fileIdTmpList = []
//         filterQuickList.forEach(item => {
//             if(item.media_id.indexOf(',') !== -1) {
//                 fileIdTmpList = [...fileIdTmpList, ...item.media_id.split(',')]
//             } else {
//                 fileIdTmpList.push(item.media_id)
//             }
//         })
//         const fileAllList = await getFileList(getFileParams, {})
//         let fileList = []
//         fileIdTmpList.forEach((item) => {
//             const fileIndex = fileAllList.data.records.findIndex((fileItem) => {
//                 return  fileItem.id == item
//             })
//             if(fileIndex !== -1) {
//                 fileList.push(fileAllList.data.records[fileIndex])
//             }
//         })
//         if(terminalId > 0) {
//           if(fileType == 1) {
//             resolve(fileAllList.data.records)
//           } else {
//             resolve(fileList)
//           }
//         } else {
//             reject('请传入正确的id')
//         }
//     })
// }
